package guiCode;

import java.sql.SQLException;

import basic.ClientConsole;

import com.sun.rowset.CachedRowSetImpl;

import flexibility.userData;
import basic.ClientConsole;

public class parentViewCode {
	
	public Integer  ParentIDId;
	private userData userInfo = new userData();
	private CachedRowSetImpl crs;
	private int currentSemsterID;
	
	private ClientConsole startConnection;
	public String parentBlockedToArr[];   //contain all Student ID which the parent block to

	
	
	public void setID(Integer whoAmI){
		this.ParentIDId=whoAmI;
	}
	public void setConnection(ClientConsole conn){
		startConnection= conn;
	}
	
	public ClientConsole getConnection() {
		return  this.startConnection;
	}
	public String getParentName() {
		
		userInfo.deleteAll();// reset user info
		userInfo.addData(68);
		userInfo.addData(1);
		userInfo.addData(ParentIDId);
		startConnection.acceptMsg(userInfo);
		
		crs=startConnection.getResults();
		try{
		crs.next();
		return 	crs.getString("parentLastName").concat(", ").concat(crs.getString("parentFirstName"));
		} 
		catch (SQLException e) {
			e.printStackTrace();
			return null;
			
		}
		
	}
public CachedRowSetImpl getParentStudents() {
	//	String s[] = new String[1000];
		userInfo.deleteAll();// reset user info
		userInfo.addData(69);
		userInfo.addData(1);
		userInfo.addData(ParentIDId);
		userInfo.addData(currentSemsterID);
		userInfo.addData(currentSemsterID);
		startConnection.acceptMsg(userInfo);
		
		return crs=startConnection.getResults();
	/*	try {
		for(int i=1;i<=crs.size();i++){
			crs.next();
			s[i]=crs.getString("studentID").concat("  ").concat(crs.getString("studentLastName")).concat(", ").concat(crs.getString("studentFirstName"));
			} 
		}
			catch (SQLException e) {
			e.printStackTrace();
			}
		return s;*/
		}
public boolean isStudentBlocked(String studentId) {
	
	userInfo.deleteAll();// reset user info
	userInfo.addData(70);
	userInfo.addData(1);
	userInfo.addData(studentId);
	userInfo.addData(ParentIDId);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	try {
		crs.next();
		int isblk=crs.getInt(1);
	//	System.out.print(crs.getString("isBlocked"));
		if(isblk==1)
			return true;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return false;
}
public Object getStudentDetail(String StudentID) {
	Object s = null ;
	userInfo.deleteAll();// reset user info
	userInfo.addData(71);
	userInfo.addData(1);
	userInfo.addData(StudentID);
	userInfo.addData(currentSemsterID);
	startConnection.acceptMsg(userInfo);
	try {
	crs=startConnection.getResults();
	
		crs.next();
		s=crs.getString("studentPhoneNumber").concat(" ").concat(crs.getString("studentID")).concat(" ").concat(crs.getString("className")).concat(" ");
		
	}
		catch (SQLException e) {
			
		e.printStackTrace();
		}
	
	return s;
	
	
}

public void createViews(String studentID) {// queries 141-151 
	userInfo.deleteAll();// Query 141
	userInfo.addData(141);
	userInfo.addData(0);
	userInfo.addData(currentSemsterID);///////////////////////////***********//////////////////////
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	
	userInfo.deleteAll();//Query 142
	userInfo.addData(142);
	userInfo.addData(0);
	userInfo.addData(studentID);
	userInfo.addData(currentSemsterID);///////////////////////////***********//////////////////////
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	
	userInfo.deleteAll();// Query 143
	userInfo.addData(143);
	userInfo.addData(0);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	
	userInfo.deleteAll();// Query 144
	userInfo.addData(144);
	userInfo.addData(0);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	
	userInfo.deleteAll();// Query 145
	userInfo.addData(145);
	userInfo.addData(0);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	
}
public CachedRowSetImpl getPastSemesterGrades() {
	// TODO Auto-generated method stub
	return null;
}

public void deleteViews(){
	for(int i =147; i<=151; i++)
	{
		userInfo.deleteAll();// Do Drop to all Views
		userInfo.addData(i);
		userInfo.addData(0);
		startConnection.acceptMsg(userInfo);
		crs=startConnection.getResults();
	}
}

public CachedRowSetImpl getFinalTable(){
	userInfo.deleteAll();// Query 146
	userInfo.addData(146);
	userInfo.addData(1);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
	
	return crs;
}

public CachedRowSetImpl getStudentPreviousSemestersCoursegrades(String StudentID)
{

	userInfo.deleteAll();// Query 152
	userInfo.addData(152);
	userInfo.addData(1);
	userInfo.addData(StudentID);
	System.out.print("currentSemsterID="+currentSemsterID+"\n");
	userInfo.addData(currentSemsterID);
	startConnection.acceptMsg(userInfo);
	crs=startConnection.getResults();
		
	return crs;
}
	/**
	 * Initialize currentSemster value ID.
	 * @param identify 
	 */
	public void setCurrentSemester(int currSemester) {
		currentSemsterID=currSemester;
		}
	/**
	 * Receive current Semester ID
	 * @return
	 */
	public int  getCurrentSemester(){
	return currentSemsterID;
	}
		
}

